package com.mj.mes.system.SysOrganization;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by mj on 2017/3/29.
 */
@Service
@Transactional
@ConfigurationProperties(value = "sysOrganizationService")
public class SysOrganizationService {
    @Autowired
    private SysOrganizationDao sysOrganizationDao;

    /**
     * 带分页查询
     * @param pageable
     * @return
     */
    public   Page<SysOrganization> findAll(Pageable pageable) {
        return sysOrganizationDao.findAll(pageable);
    }

    /**
     * 不带分页查询
     * @return
     */
   public List<SysOrganization>findAll(){
        return sysOrganizationDao.findAll();
    }

    /**
     * 根据id集合查找
     * @param list
     * @return
     */
    public List<SysOrganization> findAll(List<Long> list){
       return sysOrganizationDao.findAll(list);
    }
    public SysOrganization findOne(Long id){
        return sysOrganizationDao.findOne(id);
    }

    /**
     * 单个添加角色
     * @param sysOrganization
     */
    void addOrganization(SysOrganization sysOrganization){
        sysOrganizationDao.save(sysOrganization);
    }

    /**
     * 批量删除
     * @param list
     * @return
     */
    boolean delete(List<SysOrganization> list){
        boolean flag=false;
        try {
            sysOrganizationDao.deleteInBatch(list);
            flag=true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    /**
     * 批量添加
     * @param list
     */
    public void saveInBanch(List<SysOrganization>list){
        sysOrganizationDao.save(list);
    }
}

